#include "ml307_board.h"
#include "protocol_app.h"
#include "device_parameter.h"

#if (_NETWOK_MODLE_TYPE_ == _ML307R_MODLE_) && (_NETWOK_FUNCTION_ENABLE_)

void Ml307DelayMs(uint16_t Ms)
{
  DelayMs(Ms);
}

ML307NetworkOperator_t Ml307GetNetworkOperator(void)
{
  uint8_t Operator = GetNetworkOperator();

  switch (Operator)
  {
  case CHINA_UNICOM:
    return ML307_CHINA_UNICOM;
  
  case CHINA_TELECOM:
    return ML307_CHINA_TELECOM;
  }

  return ML307_CHINA_MOBILE;
}

void Ml307GetMqttPublishTopic(char *pTopicOut)
{
  GetMqttPublishTopic(pTopicOut);
}

void Ml307GetMqttSubscribeTopic(char *pTopicOut)
{
  GetMqttSubscribeTopic(pTopicOut);
}

void Ml307GetMqttPassword(char *pPasswordOut)
{
  GetMqttPassword(pPasswordOut);
}

void Ml307GetServerConnectAddress(uint8_t *pMaskAddrOut)
{
  GetServerConnectAddress(pMaskAddrOut);
}

void Ml307GetDnsServerAddress(uint8_t *pMaskAddrOut)
{
  GetDnsServerAddress(pMaskAddrOut);
}

uint16_t Ml307GetServerConnectPort(void)
{
  return GetNetworkServerPort();
}

void Ml307GetNetworkDomianName(char *pMaskAddrOut)
{
  GetNetworkDomianName(pMaskAddrOut);
}

void Ml307GetMqttUserName(char *pUserNameOut)
{
  GetMqttUserName(pUserNameOut);
}

void Ml307GetDeviceMacAddress(uint8_t *pMacAddrOut)
{
  uint8_t MacAddr[ML307_DEVICE_MAC_ADDRESS_CODING_LENGTH] = {0};

  if (pMacAddrOut != NULL)
  {
    GetMACAddress(MacAddr);
    for (uint8_t i = 0; i < ML307_DEVICE_MAC_ADDRESS_CODING_LENGTH; i++)
    {
      pMacAddrOut[i] = MacAddr[(ML307_DEVICE_MAC_ADDRESS_CODING_LENGTH - 1) - i];
    }
  }
}

void Ml307ForwardIncomingData(const uint8_t *pMessagePacket, uint16_t MessageSize)
{
  ProtocolPraseMessage(SOURCE_NETWORK_TRANSMISSION, pMessagePacket, MessageSize);
}

#endif
